﻿// /////////////////////////////////// 
//  
//  
//     (c)Copyright 2001-2010 Xiaojun (David) Chen 
//        Authored and Owned Xiaojun (David) Chen 
//        All Right Reserved
//  
// /////////////////////////////////// 


using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Collections.Specialized;
using System.Data.Objects;
using CCF20Model.ModelBase;
namespace CCF20Model
{
    public class OnCall
    {
        public string Name;
        public string Mobile;
    }
    
    public class ProfileModel 
    {
        static CCF20Entities ccf20Ent = new CCF20Entities();

        public static GeneralStatu GetGeneralStatus(string statusKey)
        {
            GeneralStatu status = ccf20Ent.GeneralStatus.Where(g => g.StatusKey == statusKey).OrderByDescending(g=>g.GeneralStatusID).FirstOrDefault();
            
            if (status == null)
            {
                LoggerHelper.LogZICMonitor(string.Format("通用状态{0}为空，建立一个新的状态", statusKey));
                status = new GeneralStatu();
                status.StatusKey = statusKey;
                ccf20Ent.GeneralStatus.AddObject(status);
            }
            else
            {
                ccf20Ent.Refresh(System.Data.Objects.RefreshMode.StoreWins, status);
            }
            return status;
        }
        public static CompanyProfile GetCompanyProfile()
        {
            CompanyProfile profile = ccf20Ent.CompanyProfiles.FirstOrDefault();
            if (profile == null)
            {

                LoggerHelper.LogCCF20("公司资料为空，建立一个新的公司资料");
                profile = new CompanyProfile();
                ccf20Ent.CompanyProfiles.AddObject(profile);
            }
            return profile;
        }
        
        public static void SaveIDSUserPasswrod(string ids, string password)
        {
            CompanyProfile profile = GetCompanyProfile();
            profile.LoginName = ids;
            profile.LoginPassword = password;
            ccf20Ent.SaveChanges();

        }

        public static void SaveZICUrl(string url,bool isJava)
        {
            CompanyProfile profile = GetCompanyProfile();
            profile.ZICUrl = url;
            profile.IsJava = isJava;
            ccf20Ent.SaveChanges();

        }
        public static void Update()
        {
            ccf20Ent.SaveChanges();
        }
        public static void Update(string Operator)
        {
            CompanyProfile profile = GetCompanyProfile();
            profile.Operator = Operator;
            Update();
        }
        public static OnCall GetOnCallInfo()
        {
            CompanyProfile profile = GetCompanyProfile();
            return new OnCall
            {
                Name = profile.OnCallName,
                Mobile = profile.OnCallNumber
            };
        }
        

    }
}
